<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的笔记</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #333;
            overflow-x: hidden;
        }

        .container {
            max-width: 100%;
            padding: 20px;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            min-height: 100vh;
            box-shadow: -2px 0 20px rgba(0, 0, 0, 0.1);
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #e9ecef;
        }

        .header h1 {
            font-size: 24px;
            color: #2c3e50;
            margin: 0;
        }

        .note-count {
            color: #6c757d;
            font-size: 14px;
        }

        .add-note-btn {
            width: 100%;
            padding: 15px;
            background: #111827;
            box-shadow: 0px 2px 4px -2px rgba(0, 0, 0, 0.10), 0px 4px 6px -1px rgba(0, 0, 0, 0.10), 0px 0px 0px 0px rgba(0, 0, 0, 0.00), 0px 0px 0px 0px rgba(0, 0, 0, 0.00);
            border-radius: 8px;
            color: #FDFDFD;
            font-family: "Alibaba PuHuiTi 3.0";
            font-size: 16px;
            font-style: normal;
            font-weight: 400;
            line-height: 24px;
            text-align: center;
            border: none;
            cursor: pointer;
            margin-bottom: 20px;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            opacity: 1;
            transform: translateY(0);
        }

        .add-note-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
        }

        .add-note-btn.hiding {
            opacity: 0;
            transform: translateY(-10px);
            pointer-events: none;
        }

        .write-section {
            background: white;
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
            opacity: 0;
            visibility: hidden;
            max-height: 0;
            overflow: hidden;
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            transform: translateY(-20px);
        }

        .write-section.active {
            opacity: 1;
            visibility: visible;
            max-height: 300px;
            transform: translateY(0);
        }

        .note-input {
            width: 100%;
            min-height: 120px;
            padding: 15px;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            font-size: 14px;
            font-family: inherit;
            resize: vertical;
            margin-bottom: 15px;
            transition: border-color 0.3s ease;
            white-space: pre-wrap; /* 保持换行格式 */
            word-wrap: break-word; /* 自动换行 */
            line-height: 1.5; /* 合适的行高 */
        }

        .note-input:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }

        .write-controls {
            display: flex;
            gap: 10px;
        }

        .btn {
            flex: 1;
            padding: 10px 15px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: #111827;
            box-shadow: 0px 2px 4px -2px rgba(0, 0, 0, 0.10), 0px 4px 6px -1px rgba(0, 0, 0, 0.10), 0px 0px 0px 0px rgba(0, 0, 0, 0.00), 0px 0px 0px 0px rgba(0, 0, 0, 0.00);
            border-radius: 8px;
            color: #FDFDFD;
            font-family: "Alibaba PuHuiTi 3.0";
            font-size: 16px;
            font-style: normal;
            font-weight: 400;
            line-height: 24px;
            text-align: center;
        }



        .btn-secondary {
            background: #f8f9fa;
            color: #6c757d;
            border: 1px solid #dee2e6;
        }

        .btn-secondary:hover {
            background: #e9ecef;
        }

        .notes-grid {
            display: grid;
            gap: 15px;
            grid-template-columns: 1fr; /* 改为单列布局，自动换行 */
            margin-top: 10px;
        }

        .note-card {
            background: #FFFFFF;
            box-shadow: 0px 8px 10px -6px rgba(0, 0, 0, 0.10), 0px 20px 25px -5px rgba(0, 0, 0, 0.10), 0px 0px 0px 0px rgba(0, 0, 0, 0.00), 0px 0px 0px 0px rgba(0, 0, 0, 0.00);
            border-radius: 16px;
            padding: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            user-select: text;
            -webkit-user-select: text;
            -moz-user-select: text;
            -ms-user-select: text;
        }

        .note-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        }

        .note-preview {
            font-size: 14px;
            line-height: 1.6;
            color: #2c3e50;
            margin-bottom: 15px;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 4;
            -webkit-box-orient: vertical;
            line-clamp: 4; /* 标准属性 */
            text-overflow: ellipsis;
            max-height: 6.4em; /* 回退方案 */
            white-space: pre-wrap; /* 保持换行和空格 */
            word-wrap: break-word; /* 长单词自动换行 */
            word-break: break-word; /* 确保换行 */
        }

        /* 链接样式 */
        .note-preview a, 
        .modal-text a,
        .note-link {
            color: #4285f4;
            text-decoration: underline;
            word-break: break-all;
            transition: color 0.2s ease;
        }

        .note-preview a:hover, 
        .modal-text a:hover,
        .note-link:hover {
            color: #3367d6;
            text-decoration: none;
        }

        /* 确保链接在卡片中的点击区域 */
        .note-preview a,
        .note-preview .note-link {
            position: relative;
            z-index: 10;
        }

        .note-meta {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 12px;
            color: #6c757d;
            border-top: 1px solid #f1f3f4;
            padding-top: 10px;
        }

        .note-time {
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .note-actions {
            color: #667eea;
            font-size: 11px;
            opacity: 0.7;
            transition: opacity 0.3s ease;
        }

        .note-card:hover .note-actions {
            opacity: 1;
        }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #6c757d;
        }

        .empty-state .emoji {
            font-size: 48px;
            margin-bottom: 15px;
            display: block;
        }

        .empty-state h3 {
            margin-bottom: 10px;
            color: #495057;
        }

        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(5px);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
        }

        .modal.active {
            opacity: 1;
            visibility: visible;
        }

        .modal-content {
            background: white;
            border-radius: 16px;
            padding: 30px;
            max-width: 500px;
            width: 90%;
            max-height: 70vh;
            overflow-y: auto;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
            transform: scale(0.9);
            transition: transform 0.3s ease;
        }

        .modal.active .modal-content {
            transform: scale(1);
        }

        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 2px solid #f1f3f4;
        }

        .modal-title {
            font-size: 18px;
            font-weight: 600;
            color: #2c3e50;
        }

        .close-btn {
            background: none;
            border: none;
            font-size: 24px;
            color: #6c757d;
            cursor: pointer;
            padding: 5px;
            border-radius: 50%;
            transition: all 0.3s ease;
        }

        .close-btn:hover {
            background: #f8f9fa;
            color: #495057;
        }

        .modal-text {
            font-size: 15px;
            line-height: 1.7;
            color: #2c3e50;
            margin-bottom: 20px;
            white-space: pre-wrap; /* 保持原始格式，包括换行 */
            word-wrap: break-word; /* 长单词自动换行 */
            word-break: break-word; /* 确保换行 */
            max-height: 400px; /* 限制最大高度 */
            overflow-y: auto; /* 超出时滚动 */
        }

        .modal-time {
            font-size: 13px;
            color: #6c757d;
            text-align: center;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 8px;
            margin-bottom: 15px;
        }

        .modal-actions {
            display: flex;
            gap: 10px;
            justify-content: center;
        }

        .edit-input {
            width: 100%;
            min-height: 200px;
            padding: 15px;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            font-size: 14px;
            font-family: inherit;
            resize: vertical;
            margin-bottom: 15px;
            transition: border-color 0.3s ease;
            white-space: pre-wrap;
            word-wrap: break-word;
            line-height: 1.5;
        }

        .edit-input:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }

        .btn-danger {
            background: #dc3545;
            color: white;
        }

        .btn-danger:hover {
            background: #c82333;
            transform: translateY(-1px);
        }

        .status {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 12px 20px;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            z-index: 2000;
            transform: translateX(400px);
            transition: transform 0.3s ease;
        }

        .cloud-form {
            margin: 20px 0;
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #2c3e50;
        }

        .cloud-input {
            width: 100%;
            padding: 10px;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            font-size: 14px;
            transition: border-color 0.3s ease;
            box-sizing: border-box;
        }

        .cloud-input:focus {
            outline: none;
            border-color: #667eea;
        }

        .cloud-status {
            margin-top: 10px;
            padding: 8px;
            border-radius: 5px;
            font-size: 12px;
            text-align: center;
            display: none;
        }

        .cloud-status.success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .cloud-status.error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .cloud-status.loading {
            background-color: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }

        .status.show {
            transform: translateX(0);
        }

        .status.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .status.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .action-buttons {
            display: flex;
            gap: 6px;
            margin-bottom: 20px;
        }

        .action-btn {
            flex: 1;
            padding: 8px 12px;
            background: #F3F4F6;
            box-shadow: 0px 2px 4px -2px rgba(0, 0, 0, 0.10), 0px 4px 6px -1px rgba(0, 0, 0, 0.10), 0px 0px 0px 0px rgba(0, 0, 0, 0.00), 0px 0px 0px 0px rgba(0, 0, 0, 0.00);
            border-radius: 8px;
            color: #111827;
            font-family: "Alibaba PuHuiTi 3.0";
            font-size: 16px;
            font-style: normal;
            font-weight: 400;
            line-height: 24px;
            text-align: center;
            border: none;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .action-btn:hover {
            background: #e9ecef;
            border-color: #adb5bd;
        }

        /* 响应式设计 */
        @media (max-width: 400px) {
            .container {
                padding: 15px;
            }
            
            .modal-content {
                padding: 20px;
                width: 95%;
            }
            
            .note-card {
                padding: 15px;
            }
        }
        
        /* 针对较宽的侧边栏优化 */
        @media (min-width: 500px) {
            .notes-grid {
                grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📝 我的笔记</h1>
            <div class="note-count" id="noteCount">0 条笔记</div>
        </div>

        <button class="add-note-btn" id="addNoteBtn">
            ✨ 新建笔记
        </button>

        <div class="write-section" id="writeSection">
            <textarea 
                class="note-input" 
                id="noteInput" 
                placeholder="在这里写下你的想法..."
                autofocus
            ></textarea>
            <div class="write-controls">
                <button class="btn btn-primary" id="saveNote">
                    💾 保存笔记
                </button>
                <button class="btn btn-secondary" id="cancelWrite">
                    ❌ 取消
                </button>
            </div>
        </div>

        <div class="action-buttons">
            <button class="action-btn" id="exportNotes">📤 导出</button>
            <button class="action-btn" id="cloudSyncBtn">☁️ 云端</button>
            <button class="action-btn" id="clearAllNotes">🗑️ 清空</button>
        </div>

        <div class="notes-grid" id="notesList">
            <!-- 笔记卡片将在这里动态生成 -->
        </div>
    </div>

    <!-- 查看笔记的模态框 -->
    <div class="modal" id="noteModal">
        <div class="modal-content">
            <div class="modal-header">
                <div class="modal-title">📖 笔记详情</div>
                <button class="close-btn" id="closeModal">&times;</button>
            </div>
            <div class="modal-text" id="modalText"></div>
            <div class="modal-time" id="modalTime"></div>
            <div class="modal-actions">
                <button class="btn btn-primary" id="editNoteBtn">✏️ 编辑</button>
                <button class="btn btn-danger" id="deleteNoteBtn">🗑️ 删除</button>
            </div>
        </div>
    </div>

    <!-- 编辑笔记的模态框 -->
    <div class="modal" id="editModal">
        <div class="modal-content">
            <div class="modal-header">
                <div class="modal-title">✏️ 编辑笔记</div>
                <button class="close-btn" id="closeEditModal">&times;</button>
            </div>
            <textarea 
                class="edit-input" 
                id="editInput" 
                placeholder="编辑你的笔记内容..."
            ></textarea>
            <div class="modal-time" id="editModalTime"></div>
            <div class="modal-actions">
                <button class="btn btn-primary" id="saveEditBtn">💾 保存修改</button>
                <button class="btn btn-secondary" id="cancelEditBtn">❌ 取消</button>
            </div>
        </div>
    </div>

    <!-- 云端登录模态框 -->
    <div class="modal" id="cloudModal">
        <div class="modal-content">
            <div class="modal-header">
                <div class="modal-title">☁️ 云端同步</div>
                <button class="close-btn" id="closeCloudModal">&times;</button>
            </div>
            <div class="cloud-form">
                <div class="form-group">
                    <label for="cloudUsername">用户名:</label>
                    <input type="text" id="cloudUsername" placeholder="请输入用户名" class="cloud-input">
                </div>
                <div class="form-group">
                    <label for="cloudPassword">密码:</label>
                    <input type="password" id="cloudPassword" placeholder="请输入密码" class="cloud-input">
                </div>
                <div class="cloud-status" id="cloudStatus"></div>
            </div>
            <div class="modal-actions">
                <button class="btn btn-primary" id="cloudLoginBtn">🔑 登录并同步</button>
                <button class="btn btn-success" id="cloudDownloadBtn">📥 下载笔记</button>
                <button class="btn btn-secondary" id="cancelCloudBtn">❌ 取消</button>
            </div>
        </div>
    </div>

    <!-- 状态提示 -->
    <div class="status" id="status"></div>

    <script src="sidepanel.js"></script>
</body>
</html>
